<?php
C_base::yn_file('base'.DS.'adminbase.php');
class admain extends adminbase
{
	var $_vpath='admin/';  //定义调用模板所属一级文件夹
	
	function __construct(){
		parent::__construct();
		$this->titl = '后台管理';
		$this->xurl = $this->_url.'/admin/?act=main';
	}
	
	function index(){//登录
		
	}
	
	function login(){//登录判断
		extract($this->_post1());
		$aa = C_base::M('admin.base')->cha(array('username'=>$username,'password'=>md5($passwd)));
		if($aa){
			if($aa['sjid'] != 0 && $aa['sd'] == 1){
				exit('-1');//管理员被锁定
			}
			$this->Ses('admin_id',$aa['id']);//登录id
			$this->Ses('admin_user',$aa['username']);//登录用户			
			if($aa['sjid'] == 0){
				$qx = 0;
			}else{
				$r = C_base::M('admin.xitonggl')->zu_s(array('id'=>$aa['zu']));
				$qx = explode(',',$r['qx']);
			}
			$this->Ses('admin_quanxian',$qx);//权限
			exit('登录成功');
		}else{
			exit('登录失败');
		}
	}
	
	function logout(){//退出
		$this->Ses('admin_id','');
		$this->Ses('admin_user','');
		$this->Ses('admin_quanxian','');
		$this->_alert_location($this->_url.'/admin');
	}
	
	function main(){//后台管理中心
		$this->tit = '系统配置';
		$this->sfdl();
		$this->rs = C_base::M('admin.base')->con_s();//读取网站设置
		
	}
	
	function settings(){//修改密码
		$this->tit = '修改密码';
		$this->sfdl();
		
	}
	
	function xgmm(){//修改密码
		$this->_is_html=1;
		$this->sfdl();
		if($this->_post('pass') && $this->_post('xpass') && $this->_post('xxpass')){
			$a = array('id'=>$this->Ses('admin_id'),'password'=>md5($this->_post('pass')));
			$aa = C_base::M('admin.base')->cha($a);
			if($aa){
				if($this->_post('xpass') == $this->_post('xxpass')){
					if($this->_post('xpass') == $this->_post('pass')){
						exit('新密码不能与原密码相同');
					}elseif($this->_post('xpass') == ''){
						exit('新密码不能为空');
					}else{
						$b=array('id'=>$aa['id'],'password'=>md5($this->_post('xpass')));
						$bb = C_base::M('admin.base')->xiu(array('id'=>$aa['id']),$b);
						if(@$bb){
							$this->Ses('admin_id','');
							$this->Ses('admin_user','');
							$this->Ses('admin_quanxian','');
							exit('修改成功');
						}else{
							exit('修改失败');
						}
					}
				}else{
					exit('两次密码不一致');
				}
			}else{
				exit('原密码错误');
			}
		}else{
			exit('密码不能为空');
		}
	}

	function sccache(){
		$this->_is_html = 1;
		$this->sfdl();
		$html = V_DIR.'html'.DS.'cache'.DS;//路径
		$this->cachesc($html);
		$admin = V_DIR.'admin'.DS.'cache'.DS;
		$this->cachesc($admin);
		$this->_cuowu('清除成功!');
	}
	
	function cachesc($lj){//删除缓存
		$dh = opendir($lj);//opendir打开目录句柄
		while ($file = readdir($dh)){//从目录句柄中读取条目
			if ($file != "." && $file != "..") {
				$fullpath = $lj."/".$file;
				if (!is_dir($fullpath)){//判断给定文件名是否是一个目录
					unlink($fullpath);//删除文件
				}
			}
		}
		closedir($dh);//关闭目录句柄
	}
	
	function datu(){
		
	}
	
	function upfile(){//上传图片
		$this->id = @$this->_get('id');//图片返回id
		$this->t = @$this->_get('type');//type=1单张图片,type=2多张图片累加
		$this->src = @$this->_get('src');//图片路径id
	}
	
	function uptp(){//上传图片
		$this->id = @$this->_get('id');
		$this->t = @$this->_get('type');
		$this->src = @$this->_get('src');
		$this->tplj = C_base::dybase('util')->sctp('logo');
	}
	
	function get_diqu(){//获取地区
		$id = $this->_post('id');
		$str = '<option value="0">请选择</option>';
		if($id != 0){
			$rs = C_base::M('admin.port')->linkage_ss(array('parent_id'=>$id));
			if(@$rs){
				foreach ($rs as $k=>$v){
					$str .= '<option value="'.$v['area_id'].'">'.$v['area_name'].'</option>';
				}
			}
		}
		echo $str;
	}
	
	function get_zhiwei(){//获取职位
		$id = $this->_post('id');
		$str = '<option value="0">请选择</option>';
		if($id != 0){
			$rs = C_base::M('admin.recruit')->job_ss(array('sid'=>$id));
			if(@$rs){
				foreach ($rs as $k=>$v){
					$str .= '<option value="'.$v['id'].'">'.$v['name'].'</option>';
				}
			}
		}
		echo $str;
	}
	
/*************路由开始*******************/
	function tempgl(){//模板
		$this->_is_html=1;
		C_base::own('admin.tempgl');
	}
	
	function xitong(){//系统管理
		$this->_is_html=1;
		C_base::own('admin.xitonggl');
	}
	
	function pinglun(){//评论管理
		$this->_is_html=1;
		C_base::own('admin.pinglungl');
	}
	
	function recruit(){//招聘
		$this->_is_html = 1;
		C_base::own('admin.recruit');
	}
	
}